package cn.hdu.liang.observer.swing;

import javax.swing.*;
import java.awt.*;

public class SwingObserverExample {
    JFrame frame;

    public static void main(String[] args) {
        SwingObserverExample example = new SwingObserverExample();
        example.go();
    }

    private void go() {
        frame = new JFrame();
        JButton button = new JButton("我应该做吗");
        button.addActionListener(event -> System.out.println("勿以恶小而为之"));
        button.addActionListener(event -> System.out.println("无毒不丈夫"));

        /*button.addActionListener(new AngelListener());
        button.addActionListener(new DevilListener());*/

        frame.getContentPane().add(BorderLayout.CENTER, button);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(BorderLayout.CENTER, button);
        frame.setSize(300,300);
        frame.setVisible(true);
    }

    /*private class AngelListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("勿以恶小而为之");
        }
    }

    private class DevilListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("无毒不丈夫");
        }
    }*/
}
